<div class="main layui-clear">
    <div class="wrap">
        <div class="content detail">
            <div class="fly-panel detail-box">
                <h1>
                    <?php echo $question['title'] ?>
                </h1>
                <div class="fly-tip fly-detail-hint">
                    <span>
                       <?php echo $question['status'] ?> 
                    </span>
                    <div class="jie-admin-box" data-id="8770">
                    </div>
                    <div class="fly-list-hint">
                        <a href="#comment">
                            <i class="iconfont" title="回答">
                                
                            </i>
                            <?php echo $question['answer_num'] ?>
                        </a>
                        <i class="iconfont" title="人气">
                            
                        </i>
                        <?php echo $question['view_num'] ?>
                    </div>
                </div>
                <div class="detail-about">
                    <a class="jie-user" href="{:U('home/u/index',array('id'=>$question['uid']))}">
                        <img src="__ROOT__/<?php echo $question['face'] ?>"
                        alt="玉笔书离殇">
                        <cite>
                            <?php echo $question['nickname'] ?>
                            <em>
                                发布于<?php echo CT($question['create_time']) ?>
                            </em>
                        </cite>
                    </a>
                    <div class="detail-hits" id="LAY_jieAdmin" data-id="8770">
                        <span style="color:#FF7200">
                            悬赏：<?php echo $question['kiss_num'] ?>飞吻
                        </span>
                        <span class="layui-btn layui-btn-mini jie-admin " type="collect" data-type="add">
                            收藏
                        </span>
                    </div>
                </div>
                <div class="detail-body photos">
                    <?php echo htmlspecialchars_decode($question['content'])  ?>
                </div>
            </div>
            <div class="fly-panel detail-box" style="padding-top: 0;">
                <ul class="jieda photos" id="jieda">
                    <?php if(empty($answers)){ ?>
                        <li class="fly-none">
                            没有任何回答
                        </li>
                    <?php }else{ ?>
                        <?php foreach ($answers as  $row) { ?>
                            <li data-id="30429">
                                <a name="item-1491000319505">
                                </a>
                                <div class="detail-about detail-about-reply">
                                    <a class="jie-user" href="{:U('home/u/index',array('id'=>$row['uid']))}">
                                        <img src="__ROOT__/<?php echo $row['face'] ?>"
                                        alt="心灵的孤僻" layer-index="2">
                                        <cite>
                                            <i>
                                                <?php echo $row['nickname'] ?>
                                            </i>
                                        </cite>
                                    </a>
                                    <div class="detail-hits">
                                        <span>
                                            <?php echo CT($row['create_time']) ?>
                                        </span>
                                    </div>
                                </div>
                                <div class="detail-body jieda-body">
                                    <?php echo htmlspecialchars_decode($row['content']) ?>
                                </div>
                                <div class="jieda-reply">
                                    <span class="jieda-zan " type="zan">
                                        <i class="iconfont icon-zan">
                                        </i>
                                        <em>
                                           <?php echo $row['zan_num'] ?>
                                        </em>
                                    </span>
                                    <span type="reply" class='xbsreply' nickname="<?php echo $row['nickname'] ?>">
                                        <i class="iconfont icon-svgmoban53">
                                        </i>
                                        回复
                                    </span>
                                </div>
                            </li>
                        <?php } ?>
                    <?php } ?>
                </ul>
                <div class="layui-form layui-form-pane">
                    <form action="" method="post">
                        <div class="layui-form-item layui-form-text">
                            <a name="comment">
                            </a>
                            <div class="layui-input-block">
                                
                                <textarea id="L_content" name="content" required="" lay-verify=""
                                placeholder="我要回答" class="layui-textarea fly-editor" style="height: 150px;"></textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <input type="hidden" name="qid" value="<?php echo $question['id'] ?>">
                            <button class="layui-btn" lay-filter="add" lay-submit="">
                                提交回答
                            </button>
                        </div>
                    </form>
                    <p id="xbs" contenteditable="true" placeholder="我要回答" class="layui-textarea fly-editor" style="height: 150px;width:300px;bgcolor:red"></p>
                    <a href="javascript:;" id="box">sfsdf</a>
                </div>
            </div>
        </div>
    </div>
    <div class="edge">
        <dl class="fly-panel fly-list-one">
            <dt class="fly-panel-title">
                最近热帖
            </dt>
            <?php foreach ($hotView as  $row) { ?>
                <dd>
                    <a href="{:U('home/jie/index',array('id'=>$row['id']))}">
                        <?php echo $row['title'] ?>
                    </a>
                    <span>
                        <i class="iconfont">
                            
                        </i>
                        <?php echo $row['view_num'] ?>
                    </span>
                </dd>
            <?php } ?>
        </dl>
        <dl class="fly-panel fly-list-one">
            <dt class="fly-panel-title">
                最近热议
            </dt>
            <?php foreach ($hotAnsewr as  $row) { ?>
                <dd>
                    <a href="{:U('home/jie/index',array('id'=>$row['id']))}">
                        <?php echo $row['title'] ?>
                    </a>
                    <span>
                        <i class="iconfont"></i>
                        <?php echo $row['answer_num'] ?>
                    </span>
                </dd>
            <?php } ?>
        </dl>
    </div>
    
</div>
<script type="text/javascript">
    function setCaretAtEnd(field)
    {
        if ( field.createTextRange )
        {
            alert()
            var r = field.createTextRange();
            r.moveStart('character', field.value.length);
            r.collapse();
            r.select();
        }
    }

    // document.getElementById('box').onclick = function  () {
    //     document.getElementById('xbs').innerHTML='sdfsd';
    //     setCaretAtEnd(document.getElementById('xbs'));
    //     // document.getElementById('xbs').focus();
    // }


    layui.use(['form','jquery','layedit'], function(){
        var form = layui.form()
        ,layer = layui.layer,
        $= layui.jquery;
        layedit = layui.layedit;

        $('#box').click(function(event) {
            $('#xbs').focus().html('sdfsdf');
        });

        
        layedit.set({
          uploadImage: {
            url: '{:U('home/jie/uploadImage')}' //接口url
            ,type: '' //默认post
          }
        });
        
        
        index = layedit.build('L_content', {
          height: 180 //设置编辑器高度
        });

        $('.xbsreply').click(function(event) {
             layedit.xbsfocus(index);
        }); 




        //监听提交    
      form.on('submit(add)', function(data){

        content = layedit.getContent(index);

        if(content.length<20){
           layer.msg("内容不低于20", function(){}
                );
           return false;
        }
        // console.log(data);
        // 
        data.field.content = content;

        $.ajax({
            url: '{:U('home/jie/addAnswer')}',
            type: 'POST',
            dataType: 'json',
            data: data.field,
        })
        .done(function(respones) {
            if(respones.error==1){
                layer.msg(respones.info, function(){}
                );
            }else{
                layer.alert(respones.info, {icon: 6},function  () {
                    location.reload();
                });
            }
        })
        .fail(function() {
            console.log("error");
        })
        
        
      
        return false;
      });
  
  
});

</script>